import request from '@/utils/request'

const envapi = process.env.VUE_APP_ADV_OCEAN_API

// 巨量 任务列表
export function taskList(data) {
  const params = {
    filtering: [],
    // 分页
    page: data.page,
    page_size: data.page_size,
    order_by: data.order_by,
    order_type: data.order_type,
  }
  if (data.id) params.filtering.push({ field: 'id', operator: 'EQUALS', value: data.id }) 
  if (data.task_status)  params.filtering.push({ field: 'task_status', operator: 'EQUALS', value: data.task_status })
  if (data.task_type) params.filtering.push({ field: 'task_type', operator: 'EQUALS', value: data.task_type })
  if (data.created_at && data.created_at.length > 0) {
    params.filtering.push({ field: 'created_at', operator: 'GREATER_EQUALS', value: data.created_at[0] })
    params.filtering.push({ field: 'created_at', operator: 'LESS_EQUALS', value: data.created_at[1] })
  }
  return request({
    url: envapi + '/admin/task/select',
    method: 'post',
    data:params
  })
}
// 巨量 任务开启
export function taskOpen (task_id) {
  return request({
    url: envapi + '/admin/task/open',
    method:'post',
    data: { task_id:task_id }
  })
}
// 巨量 任务关闭
export function taskClose (task_id) {
  return request({
    url: envapi + '/admin/task/close',
    method:'post',
    data: { task_id:task_id }
  })
}
// 子任务 批量 列表
export function getOceanBatchCreativeList (data) {
  const params = {
    filtering:[],
    // order_by: data.order_by,
    // order_type: data.order_type,
    page: data.page,
    page_size: data.page_size
  }
  if (data.task_id) {
    params.filtering.push({
      field: 'task_id',
      operator: 'EQUALS',
      value: data.task_id
    })
  }
  if (data.account_id) {
    params.filtering.push({
      field: 'account_id',
      operator: 'EQUALS',
      value: data.account_id
    })
  }
  if (data.exec_status) {
    params.filtering.push({
      field: 'exec_status',
      operator: 'EQUALS',
      value: data.exec_status
    })
  }
  return request({
    url: envapi + '/admin/sub_task/ocean_ad_creative_create/select',
    method:'post',
    data: params
  })
}

// 子任务 批量 计划更新  (状态、预算、出价更改)
export function adUpdateTask (data) {
  return request({
    url: envapi + '/admin/sub_task/ocean_ad_update/create',
    method:'post',
    data:data
  })
}
// 子任务 批量 计划更新 列表
export function adUpdateTaskList (data) {
  return request({
    url: envapi + '/admin/sub_task/ocean_ad_update/select',
    method:'post',
    data:data
  })
}
// 子任务 批量 计划更新 详情
export function adUpdateTaskDetails(id) {
  return request({
    url: envapi + '/admin/sub_task/ocean_ad_update/read',
    method:'post',
    data:{ id:id }
  })
}

// 批量任务 详情
export function getOceanBatchCreativeDetails (id) {
  return request({
    url: envapi + '/admin/sub_task/ocean_ad_creative_create/read',
    method:'post',
    data: { id:id }
  })
}
// 批量创建
export function batchCreate (data) {
  return request({
    url: envapi + '/admin/ocean/tool/batch_create_ad_creative',
    method:'post',
    data: data
  })
}
// 子任务 同步 列表
export function getOceanSyncList (data) {
  const params = {
    filtering:[],
    // order_by: data.order_by,
    // order_type: data.order_type,
    page: data.page,
    page_size: data.page_size
  }
  if (data.task_id) {
    params.filtering.push({
      field: 'task_id',
      operator: 'EQUALS',
      value: data.task_id
    })
  }
  if (data.exec_status) {
    params.filtering.push({
      field: 'exec_status',
      operator: 'EQUALS',
      value: data.exec_status
    })
  }
  if (data.account_id) {
    params.filtering.push({
      field: 'account_id',
      operator: 'EQUALS',
      value: data.account_id
    })
  }
  return request({
    url: envapi + '/admin/sub_task/ocean_sync/select',
    method:'post',
    data: params
  })
}
// 子任务 同步 详情
export function getOceanSyncDetails (id) {
  return request({
    url: envapi + '/admin/sub_task/ocean_sync/read',
    method:'post',
    data: { id:id }
  })
}
